package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import pojo.Offices;
import pojo.OfficesPage;
import service.OfficesService;

/**
 * @author 李主席
 * @create 2020-12-09 9:13
 */

@Controller
public class OfficesController {
    @Autowired
    private OfficesService officesService;
    private Integer pageSize = 3;

    @RequestMapping("all_offices")
    public String getAlloffices(Integer page, Model model) {
        Integer pid = page == null ? 1 : page;
        OfficesPage officesPage = officesService.getAllUsers(pid, pageSize);
        model.addAttribute("officesPage", officesPage);
        return "all_offices";
    }

    @RequestMapping("goto_add")
    public String gotoAddUser() {
        return "add_offices";
    }

    @RequestMapping("add_offices")
    public String addoffices(Offices offices, Model model) {

        Integer i = officesService.addOneOffice(offices);
        if (i > 0) {
            model.addAttribute("message", "新增成功");
            return "redirect:/all_offices.action";
        } else {
            model.addAttribute("message", "新增失败");
        }
        return "add_offices";
    }
}
